package com.atguigu.scala.test

import scala.io.Source

/**
 * @author lizikuan
 * @date 2021/5/24 18:32
 */
object Test2 {
  def main(args: Array[String]): Unit = {
    //1、获取没有农贸市场的所有省份


    val allprovince = Source.fromFile("./datas/allprovince.txt").getLines().toList
    val product = Source.fromFile("./datas/product.txt").getLines().toList
    val list = product.map(_.split(",").toList).filter(x=>x.length==6).map(_.apply(4)).distinct
//    println(list)
    println(allprovince.diff(list))
    //List(海南, 贵州, 云南, 台湾, 西藏, 香港, 澳门)

    //2、获取农产品种类最多的三个省份
    product.map(_.split(",").toList)
      .filter(x=>x.length==6)
      .groupBy(_.apply(4))
      .map(x=>x._1->x._2.map(_.head).distinct.size)
      .toList.sortBy(x=>x._2)
      .takeRight(3)
      .foreach(x=>println(x))


    //3、获取每个省份中农产品种类最多的三个农贸市场
     product.map(_.split(",").toList)
       .filter(_.length == 6)
       .groupBy(_.apply(4))
       .map(x=>x._1->x._2.map(x=>List(x.head,x.apply(3))))
       .map(x => x._1 -> x._2.groupBy(_.apply(1)).map(x=>x._1->x._2.map(_.head).distinct.size).toList.sortBy(_._2).takeRight(3))
       .foreach(x=>println(x))


  }
}
